package org.liquidByte.trafficMustang.androidApp.listview.row;

import java.security.InvalidParameterException;

import org.liquidByte.trafficMustang.androidApp.listview.adapter.RowAdapter;

import android.view.View;

public abstract class ModelListViewRow<T> extends ListViewRow {

	private RowAdapter<T> parentAdapter;
	private T model;
	
	protected ModelListViewRow(RowAdapter<T> parentAdapter, View view) {
		super(view);
		if (parentAdapter == null) {
			throw new InvalidParameterException("parentAdapter is null");
		}
		this.parentAdapter = parentAdapter;
	}

	public T getModel() {
		return model;
	}

	public void setModel(T model) {
		if (!(this.model == null && model == null ||
			  this.model != null && model != null && this.model.equals(model))) {
			this.model = model;
			this.bindToView();
		} else {
			this.model = model;
		}
	}
	
	protected void remove() {
		this.parentAdapter.remove(this.getModel());
	}
	
	public abstract void bindToView();
}
